package xia;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.Toast;
import com.xuanfu_button.SelfDialog_with_type;
import com.xuanfu_button.XuanfuButton_blank;
import com.zlp.mymapviewproject.mymapview.MyMapPointWithTitleView_xuanfu_mark;
import org_rosjava.ros.android.android_tutorial_map_viewer.My_map;
public class XuanfuButton_Click_blank_menu {
    public static void showInputDialog(final Double downX, final Double downY, final MyMapPointWithTitleView_xuanfu_mark myMapPointWithTitleView_xuanfu_mark) {
        final SelfDialog_with_type selfDialog;
        selfDialog = new SelfDialog_with_type(My_map.getinstance());
        selfDialog.setYesOnclickListener("确定", new SelfDialog_with_type.onYesOnclickListener() {
            @Override
            public void onYesClick() {
                if(!selfDialog.getInput().equals(""))
                {
                    if(My_map.getinstance().mark_coordinatejsondata_last!=null)
                    {
                        boolean is_have_same_name=false;
                        for(int i=0;i<My_map.getinstance().mark_coordinatejsondata_last.mark_coordinate.size();i++)
                        {
                            String name=My_map.getinstance().mark_coordinatejsondata_last.mark_coordinate.get(i).name;
                            if(name.contains(My_map.point_type_flag))
                            name=name.substring(0,name.indexOf(My_map.point_type_flag));
                            if(selfDialog.getInput().equals(name))
                            {
                                is_have_same_name=true;
                                break;
                            }
                        }
                        if(is_have_same_name==false)
                        {
                                String data_value = "mark:coordinate_add:" + downX + "," + downY + ",0,"+myMapPointWithTitleView_xuanfu_mark.getpointIcon().get_dir_x()+","+myMapPointWithTitleView_xuanfu_mark.getpointIcon().get_dir_y()+","+myMapPointWithTitleView_xuanfu_mark.getpointIcon().get_dir_z()+","+myMapPointWithTitleView_xuanfu_mark.getpointIcon().get_dir_w()+":" + selfDialog.getInput()+selfDialog.gettype();
                                My_map.getinstance().myRos_sendTextPublish.sendStringData(data_value);
                                selfDialog.dismiss();
                                My_map.getinstance().myMapView.rmMapPoint_xuanfu_mark();
                                My_map.getinstance().myMapView.rmMapPoint_tmp();
                                if (My_map.getinstance().isAdded) {
                                    XuanfuButton_Create.removeXuanfuButtonView();
                                    My_map.getinstance().isAdded = false;
                                }
                        }
                        else
                        {
                            Toast.makeText(My_map.getinstance(),"名字重复",Toast.LENGTH_LONG).show();
                        }
                    }
                    else
                        Toast.makeText(My_map.getinstance(),"获取数据失败",Toast.LENGTH_LONG).show();
                }
                else
                    Toast.makeText(My_map.getinstance(),"输入内容不能为空",Toast.LENGTH_LONG).show();
            }
        });
        selfDialog.setNoOnclickListener("取消", new SelfDialog_with_type.onNoOnclickListener() {
            @Override
            public void onNoClick() {
                My_map.getinstance().myMapView.rmMapPoint_xuanfu_mark();
                My_map.getinstance().myMapView.rmMapPoint_tmp();
                selfDialog.dismiss();
            }
        });
        selfDialog.show();
    }
    public static void  init_xuanfuButton_blank(float fingerX, float fingerY, final double pointX, final double pointY, final MyMapPointWithTitleView_xuanfu_mark myMapPointWithTitleView_xuanfu_mark)
    {
        try {
            DisplayMetrics dm = new DisplayMetrics();
            My_map.getinstance().getWindowManager().getDefaultDisplay().getMetrics(dm);
            int screenWidth = dm.widthPixels;
            int screenHeight = dm.heightPixels;
            My_map.getinstance().xuanfuButton_blank = new XuanfuButton_blank(My_map.getinstance().getApplicationContext());
            My_map.getinstance().xuanfuButton_blank.setButton1Text("添加餐桌");
            My_map.getinstance().xuanfuButton_blank.setButton2Text("取消");
            int xuanfuWidth=0;
            int xuanfuHeight=0;
            if(My_map.getinstance().xuanfuButton_blank.getlinearLayout_xuanfuWidth()!=0&&My_map.getinstance().xuanfuButton_blank.getlinearLayout_xuanfuHeight()!=0) {
                xuanfuWidth = My_map.getinstance().xuanfuButton_blank.getlinearLayout_xuanfuWidth();
                xuanfuHeight = My_map.getinstance().xuanfuButton_blank.getlinearLayout_xuanfuHeight();
            }
            else
            {
                xuanfuWidth = 200;
                xuanfuHeight = 200;
            }
            My_map.getinstance().params_xuanfu = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
            My_map.getinstance().params_xuanfu.width=xuanfuWidth;
            My_map.getinstance().params_xuanfu.height=xuanfuHeight;
            My_map.getinstance().xuanfu_x=(int)fingerX-xuanfuWidth-50;
            My_map.getinstance().xuanfu_y=(int)fingerY;
            if(My_map.getinstance().xuanfu_x<=0)
                My_map.getinstance().xuanfu_x=(int)fingerX+50;
            if((fingerY+xuanfuHeight)>=screenHeight)
                My_map.getinstance().xuanfu_y=(int)fingerY-xuanfuHeight;
            My_map.getinstance().params_xuanfu.leftMargin=My_map.getinstance().xuanfu_x;
            My_map.getinstance().params_xuanfu.topMargin=My_map.getinstance().xuanfu_y;
            My_map.getinstance().xuanfuButton_blank.button1().setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    if(My_map.getinstance().isAdded)
                    {
                        try {
                            ((ViewGroup)My_map.getinstance().xuanfuButton_blank.getParent()).removeView(My_map.getinstance().xuanfuButton_blank);
                        } catch (Exception e) {
                        }
                        My_map.getinstance().isAdded = false;
                    }
                    showInputDialog(My_map.getinstance().marked_positionInfo_x, My_map.getinstance().marked_positionInfo_y, myMapPointWithTitleView_xuanfu_mark);
                }
            });

            My_map.getinstance().xuanfuButton_blank.button2().setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    My_map.getinstance().myMapView.rmMapPoint_xuanfu_mark();
                    My_map.getinstance().myMapView.rmMapPoint_tmp();
                    if(My_map.getinstance().isAdded) {
                        try {
                            ((ViewGroup)My_map.getinstance().xuanfuButton_blank.getParent()).removeView(My_map.getinstance().xuanfuButton_blank);
                        } catch (Exception e) {
                        }
                        My_map.getinstance().isAdded = false;
                    }
                }
            });
        } catch (Exception e) {
        }
    }
}
